var nowpage = 1
jeDate({
    dateCell:"#startTime",
    format:"YYYY年MM月DD日 hh:mm:ss",
    isinitVal:true,
    isTime:true, //isClear:false,
    minDate:"2014-09-19 00:00:00",
    okfun:function(val){alert(val)}
})
jeDate({
    dateCell:"#endTime",
    format:"YYYY年MM月DD日 hh:mm:ss",
    isinitVal:true,
    isTime:true, //isClear:false,
    minDate:"2014-09-19 00:00:00",
    okfun:function(val){alert(val)}
})

laydate.render({
    elem: '#timedate1'
});
laydate.render({
    elem: '#timedate2'
});
var form1 = {
    size: 10,
    page: 1,
    orderCode: "",
    merchantNo: "",
    lowPrice: null,
    highPrice: null,
    status: "",
    startTime: "",
    endTime:""
}
var form2 = {
total: 2000,
pageSize: 10,
showTotal: true,
showTo: true,
change: function ( i ) {
    createContent( i );
}
}
var $content = $( ".content" );
function getTableData(form1){
form1.startTime = document.getElementById('startTime').value.replace('年','-').replace('月','-').replace('日','')
form1.endTime = document.getElementById('endTime').value.replace('年','-').replace('月','-').replace('日','')
$.ajax({
url:initObj.url + "/api/transfer/findTransfer",
// data:JSON.stringify(form1),
data:form1,
datatype:'json',
type:'get',
beforeSend: function(request) {
   request.setRequestHeader("token", form.token);
//    console.log(form.token)
},
success:function(res){
    console.log(res)
    document.getElementById('selectAll').innerHTML = ""
    for(var i=0;i<res.data.content.length;i++){
        // console.log(1)
        document.getElementById('selectAll').innerHTML += 
        "<li><span style='width:10vw;font-weight:bold;display:inline-block'>"+res.data.content[i].orderCode+
        "</span><span style='width:15vw;display:inline-block'>"+res.data.content[i].sendMerchant+
        "</span><span style='width:10vw;display:inline-block'>"+res.data.content[i].amount+
        "</span><span style='width:10vw;display:inline-block'>"+res.data.content[i].createTime+
        "</span><span style='width:15vw;display:inline-block'>"+res.data.content[i].receivedMerchant+
        "</span><span class='state'><button style='margin-right:1vw;background-color:#15b68f;color:#fff' onclick='chongzhi_YES("
        +res.data.content[i].id+")'>同意</button><button style='margin-right:1vw;background-color:#f91d1d;color:#fff' onclick='chongzhi_NO("
        +res.data.content[i].id+")'>拒绝</button></span></li>"
        if(res.data.content[i].state == 'FAIL'){
            document.getElementsByClassName('state')[i].innerHTML = "申请失败"
            document.getElementsByClassName('state')[i].style.color = '#f91d1d'
            document.getElementsByClassName('state')[i].style.display = 'inline-block'
            document.getElementsByClassName('state')[i].style.width = '7.7vw'
        }else if(res.data.content[i].state == 'SUCCESS'){
            console.log(document.getElementsByClassName('state')[i])
            document.getElementsByClassName('state')[i].innerHTML = "申请成功"
            document.getElementsByClassName('state')[i].style.color = '#15b68f'
            document.getElementsByClassName('state')[i].style.display = 'inline-block'
            document.getElementsByClassName('state')[i].style.width = '7.7vw'
        }else{
        }
    }
    if(form2.total !== res.data.totalElements){
        form2.total = res.data.totalElements
        Helper.ui.page("#page-3", form2);
        nowpage++
    }
}
})
}
getTableData(form1)
function createContent (i) {
form1.page = i
getTableData(form1)
}
function changeinfo(id,value){
form1[id] = value
// console.log(form1)
}
function search(){
getTableData(form1)
}

//同意
function chongzhi_YES(id){
    $.ajax({
        url:initObj.url + "/api/transfer/updateState/" + id + '/SUCCESS',
        datatype:'json',
        type: 'put',
        beforeSend: function(request) {
            request.setRequestHeader("token", form.token);
         //    console.log(form.token)
        },
        success:function(res){
            console.log(res)
            getTableData(form1)
        }
    })
}
function chongzhi_NO(id){
    jujue_id.value = id
    jujue.style.display = 'block'
}
function jujue_close(){
   jujue.style.display = 'none'
} 
document.getElementById('jujue_OK').onclick = function(){
    var id = jujue_id.value
    var form_body = {
        reasonRefusal:jujue_liyou.value
    }
    $.ajax({
        url:initObj.url + "/api/transfer/updateState/" + id + '/FAIL',
        data:form_body,
        datatype:'json',
        type: 'put',
        beforeSend: function(request) {
            request.setRequestHeader("token", form.token);
         //    console.log(form.token)
        },
        success:function(res){
            console.log(res)
            jujue_liyou.value = ''
            jujue.style.display = 'none'
            getTableData(form1)
        }
    })
}